import forumAxios from '../utils/request'

const BASE_URL = '/article'

export async function getArticlesByUserId(userId) {
    console.log(userId);

    const resp = await forumAxios.get(BASE_URL + '/getArticlesByUserId', {
        params: {
            userId: userId
        }
    });
    console.log(resp);

    return resp
}

export async function getArticles(pageRequest) {
    console.log(pageRequest)
    const resp = await forumAxios.post(BASE_URL + '/getArticles', pageRequest);

    return resp
}

export async function gerUserIdByArticleId(articleId) {
    const resp = await forumAxios.get(BASE_URL + '/gerUserIdByArticleId', {
        params: {
            articleId: articleId
        }
    })
    return resp
}

export async function getArticleByArticleId(articleId) {
    const resp = await forumAxios.get(BASE_URL + '/getArticleByArticleId', {
        params: {
            articleId: articleId
        }
    })
    return resp
}

export async function createArticle(article) {
    const resp = await forumAxios.post(BASE_URL + '/createArticle', article)
    return resp
}

export async function updateArticle(data) {
    // console.log(data)
    const resp = await forumAxios.post(BASE_URL + `/updateArticle`, data)
        // console.log(resp);

    return resp
}

export async function deleteArticleByArticleId(articleId) {
    const resp = await forumAxios.get(BASE_URL + `/deleteArticle`, {
        params: {
            articleId: articleId
        }
    })
    return resp
}

export async function searchArticles(keyword) {
    console.log(keyword)
    const params = {
        keyword: keyword // 以键值对方式传递
    };
    const resp = await forumAxios.get(BASE_URL + '/searchArticles', {
        params: params
    });
    console.log(resp);
    return resp

}

export async function boardArticles(boardId) {
    const params = {
        boardId: boardId // 以键值对方式传递
    };
    const resp = await forumAxios.get(BASE_URL + '/boardArticles', {
        params: params
    });
    console.log(resp);
    return resp

}